/*
 * wireless.h
 *
 * Created: 2013/12/19 15:09:55
 *  Author: alivehex
 */ 


#ifndef WIRELESS_H_
#define WIRELESS_H_

#include "gpio.h"
#include "hardware.h"

typedef struct {
	union {
		uint16_t word[2];
		char byte[4];
	} header;
	uint16_t index;		// command index
	uint16_t value0;	// argument1
	uint16_t value1;	// argument2
} rf_ctrl_package_t;

typedef enum {
	SYS_ROLE_PTX,
	SYS_ROLE_PRX,
} sys_role_t;

#define RF_RET_PASS		0
#define RF_RET_FAIL		1
#define RF_RET_TIMEOUT	2

#define WIRELESS_LOWLEVEL_INIT() \
	_CONFIG_IO_OUTPUT(MOSI_PORT, MOSI_PIN);\
	_CONFIG_IO_OUTPUT(NPCS_PORT, NPCS_PIN);\
	_CONFIG_IO_OUTPUT(SPCK_PORT, SPCK_PIN);\
	_CONFIG_IO_OUTPUT(CE_PORT, CE_PIN);\
	_CONFIG_IO_OUTPUT(LED_PORT, LED_PIN);\
	_CONFIG_IO_INPUT_PULLUP(MISO_PORT, MISO_PIN);\
	_CONFIG_IO_INPUT_PULLUP(IRQ_PORT, IRQ_PIN);\
	_CLR_IO(SPCK_PORT, SPCK_PIN);\
	_SET_IO(NPCS_PORT, NPCS_PIN);\
	_CLR_IO(CE_PORT, CE_PIN);\
	_SET_IO(LED_PORT, LED_PIN);
	
int wirelessInit(void);
void wirelessWriteFIFO(const char *buf, int len);
void wirelessWrite(const char *buffer, int bufferLength);
void wirelessWriteReg(uint8_t address, uint8_t value);
uint8_t wirelessReadReg(uint8_t address);	


#endif /* WIRELESS_H_ */